<?php
class Schedule_Model_Schedule extends Promotor_Model_Scaffold
{
	protected $_dbTableClass = 'Schedule_Model_DbTable_Schedule';
	
	protected $_cachedMethods = array(
		'findScheduleInfo',
		'findOneBy' // parent::findOneBy
	);
	
	public function findScheduleInfo($schedule)
	{
		$result = array(
			'row' => null,
			'users' => array()
		);

		$row = $this->findOneBy('username', $schedule);
		if (!($row instanceof Zend_Db_Table_Row_Abstract))
		{
			$this->_setStatus(self::FAILURE);
			$this->_log(sprintf('Terminarz wizyt %s nie został odnaleziony', $schedule), Zend_Log::WARN);
			return null;
		}
		
		$result['row'] = $row->toArray();
		
		try {
			$rowset = $row->findDependentRowset('Schedule_Model_DbTable_User');
		} catch(Zend_Db_Exception $e) {
			$this->_setStatus(self::FAILURE);
			$this->_logException($e, Zend_Log::ERR);
		}
		
		if (count($rowset))
		{
			foreach ($rowset as $row)
			{
				$result['users'][$row->id] = $row->name;
			}
		}

		return $result;
	}
}